﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using eCommerce.DataAccess;

namespace eCommerce.CMS.CustomAdmin.Controls.Pages
{
    public partial class List : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
         if (!IsPostBack)
          {
            using (WebsiteDataContext websiteDataContext = new WebsiteDataContext())
			{
			    var menu = from mn in websiteDataContext.Xcms_Pages
			               select mn;
                GridView1.DataSource = menu;
				GridView1.DataBind();
			}
		  }
        }
        protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                //e.Row.Cells[1].Visible = false;
                //e.Row.Cells[2].Visible = false;
            }

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //e.Row.Cells[1].Visible = false;
                //e.Row.Cells[2].Visible = false;
                ImageButton MinButton = (ImageButton)e.Row.Cells[0].FindControl("MinBT");
                MinButton.CommandArgument = e.Row.RowIndex.ToString();
                ImageButton addButton = (ImageButton)e.Row.Cells[0].FindControl("PluseBT");
                addButton.CommandArgument = e.Row.RowIndex.ToString();
                //e.Row.Cells[3].Visible = false;
            }
        }
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string ShowHide = e.Row.Cells[2].Text;
                //ShowHide = ShowHide.Replace("0", "");
                if (ShowHide == "0" || ShowHide == "3")
                {
                    ImageButton Bt_Min = (ImageButton)e.Row.Cells[0].FindControl("MinBT");
                    Bt_Min.Visible = true;
                    ImageButton Bt_plus = (ImageButton)e.Row.Cells[0].FindControl("PluseBT");
                    Bt_plus.Visible = false;
                }
                else
                {
                    ImageButton Bt_Min = (ImageButton)e.Row.Cells[0].FindControl("MinBT");
                    Bt_Min.Visible = false;
                    ImageButton Bt_plus = (ImageButton)e.Row.Cells[0].FindControl("PluseBT");
                    Bt_plus.Visible = false;
                }
            }
        }
        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {

            if (e.CommandName == "_Show")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                GridViewRow row = GridView1.Rows[index];
                int G_Count = GridView1.Rows.Count;
                for (int i = index + 1; i < G_Count; i++)
                {
                    if (GridView1.Rows[i].Cells[2].Text == "0")
                    {
                        ImageButton Bt_Min = (ImageButton)row.Cells[0].FindControl("MinBT");
                        Bt_Min.Visible = true;
                        ImageButton Bt_plus = (ImageButton)row.Cells[0].FindControl("PluseBT");
                        Bt_plus.Visible = false;
                        break;
                    }
                    else
                    {
                        GridView1.Rows[i].Visible = true;


                    }
                    ImageButton Bt_Min1 = (ImageButton)row.Cells[0].FindControl("MinBT");
                    Bt_Min1.Visible = true;
                    ImageButton Bt_plus1 = (ImageButton)row.Cells[0].FindControl("PluseBT");
                    Bt_plus1.Visible = false;
                }

            }
            if (e.CommandName == "_Hide")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                GridViewRow row = GridView1.Rows[index];
                int G_Count = GridView1.Rows.Count;
                for (int i = index + 1; i < G_Count; i++)
                {
                    if (GridView1.Rows[i].Cells[2].Text == "0")
                    {
                        ImageButton Bt_Min = (ImageButton)row.Cells[0].FindControl("MinBT");
                        Bt_Min.Visible = false;
                        ImageButton Bt_plus = (ImageButton)row.Cells[0].FindControl("PluseBT");
                        Bt_plus.Visible = true;
                        break;
                    }
                    else
                    {
                        GridView1.Rows[i].Visible = false;


                    }
                    ImageButton Bt_Min1 = (ImageButton)row.Cells[0].FindControl("MinBT");
                    Bt_Min1.Visible = false;
                    ImageButton Bt_plus1 = (ImageButton)row.Cells[0].FindControl("PluseBT");
                    Bt_plus1.Visible = true;
                }


            }
        }

        protected void Button_Add_Click(object sender, EventArgs e)
        {
            Response.Redirect("pages.aspx?action=Add");
        }

        protected void Button_delete_Command(object sender, CommandEventArgs e)
        {


            //    //Response.Redirect("pages.aspx?action=Delete&PageID=" + e.CommandArgument);
        }

        protected void btnonclick(object sender, EventArgs e)
        {
            //MessageBox.Show("Are you sure you want to delete this page?");
        }


        protected void Button_edit_Command(object sender, CommandEventArgs e)
        {
            Response.Redirect("pages.aspx?action=Edit&PageID=" + e.CommandArgument);
        }
    }
}